<template>
  <div>
    <van-nav-bar title="修改密码" left-arrow @click-left="onClickLeft" />
    <van-form @submit="onSubmit">
      <van-field
        v-model="username"
        name="旧密码"
        label="旧密码"
        placeholder="旧密码"
        :rules="[{ required: true, message: '请填写旧密码' }]"
      />
      <van-field
        v-model="password"
        type="password"
        name="新密码"
        label="新密码"
        placeholder="新密码"
        :rules="[{ required: true, message: '请填写新密码' }]"
      />
      <div style="margin: 16px">
        <van-button round block type="info" native-type="submit"
          >提交</van-button
        >
      </div>
    </van-form>
  </div>
</template>
<script>
import Vue from "vue";
import { NavBar } from "vant";
import { Toast } from "vant";
import { Form } from "vant";
import { Field } from "vant";

Vue.use(Form);
Vue.use(Field);
Vue.use(NavBar);
export default {
  name: "changepassword",
  data() {
    return {
      username: "",
      password: "",
    };
  },
  mounted(){
      this.user_id=localStorage.getItem("userId")
      console.log(this.user_id)
  },
  methods: {
    onClickLeft() {
      this.$router.go(-1)
    },
    onSubmit(values) {
      console.log("submit", values);
      this.axios({
        method: "post",
        url: "http://localhost:3000/changepassword",
        data: {
            data:values,
            user_id:this.user_id
        },
      }).then((res)=>{
        if(res.data=="旧密码不能给新密码一样"){
            Toast("旧密码不能给新密码一样")
        }else{
          Toast("修改成功")
          this.$router.replace("/")
        }
        
      })


  // this.axios({
  //       method:"post",
  //       url:"http://localhost:3000/login",
  //       data:data1,
  //       processData: false,
  //       contentType: false,
  //     }).then((res)=>{
  //       // console.log(res)
  //       const aaa=res.data.error
  //       // console.log(res.data.error)
  //       if(aaa==1){
  //            Toast("账号或密码错误！")
  //       }else{
  //         console.log("成功")
  //       }
  //     })






    },
  },
};
</script>
<style  scoped>
/deep/.van-nav-bar__text {
  color: black;
}
/deep/.van-icon {
  color: black;
}
</style>